package net.hserver.apm.hum;

import net.hserver.apm.common.DataConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cn.hserver.core.interfaces.HumAdapter;
import cn.hserver.core.ioc.annotation.Bean;
import cn.hserver.core.queue.HServerQueue;
import cn.hserver.core.server.context.HumMessage;
import cn.hserver.core.server.handlers.Hum;

@Bean
public class DataHum implements HumAdapter {
    private static final Logger log = LoggerFactory.getLogger(DataHum.class);

    public void message(HumMessage humMessage, Hum hum) {
        if (DataConfig.APM_CONNECT.equals(humMessage.getType())){
            log.info("有连接收到。恢复连接成功");
            hum.sendMessage(new HumMessage(DataConfig.APM_LIVE, DataConfig.APM_LIVE));
        }else {
            switch (humMessage.getType()) {
                case DataConfig.APM_DATA_INFO:
                    HServerQueue.sendQueue("APM_REC", DataConfig.APM_DATA_INFO, humMessage.getData());
                    break;
                case DataConfig.APM_DATA_REQUEST_INFO:
                    HServerQueue.sendQueue("APM_REC", DataConfig.APM_DATA_REQUEST_INFO, humMessage.getData());
                    break;
                case DataConfig.APM_DATA_LOG_INFO:
                    HServerQueue.sendQueue("APM_REC", DataConfig.APM_DATA_LOG_INFO, humMessage.getData());
                    break;
                case DataConfig.APM_DATA_LINK_INFO:
                    HServerQueue.sendQueue("APM_REC", DataConfig.APM_DATA_LINK_INFO, humMessage.getData());
                    break;
                case DataConfig.APM_DATA_SQL_INFO:
                    HServerQueue.sendQueue("APM_REC", DataConfig.APM_DATA_SQL_INFO, humMessage.getData());
                    break;
            }
        }
    }
}
